package com.zyx.mpdemo.model.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * <p>课程状态枚举
 *
 * @author Yaxi.Zhang
 * @since 2022/11/21 11:36
 */
@Getter
@AllArgsConstructor
public enum CourseStatusEnums {
    DELETE(0, "删除"),
    LEARNING(1, "未学习"),
    LEARNED(2, "已学习"),
    ;

    @EnumValue
    private final Integer code;
    private final String desc;

    public static CourseStatusEnums of(Integer code) {
        Objects.requireNonNull(code);
        return Stream.of(values())
                .filter(it -> it.getCode().equals(code))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException(code + " not exists"));
    }

}
